<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试post请求</title>
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>

<h2>这是一个用于测试填充数据库表单的实验</h2>
<!-- 一个简单的表单，发送 POST 请求 -->
<div>
    <input type="text" id="name" placeholder="初始姓名">
</div>
<div>
    <input type="text" id="lastName" placeholder="最后姓名">
</div>
<button type="button" onclick="sendRequest()">提交</button>

<script>
    let a = document.getElementById('name')
    let b = document.getElementById('lastName')

    function sendRequest() {
        let
            oReq = new XMLHttpRequest();
        oReq.open("post", "http://localhost:3000/api/register", true);
        oReq.setRequestHeader("Content-Type", "application/json");
        oReq.send(JSON.stringify({'name': a.value, 'lastName': b.value}));
    }
</script>
</body>
</html>

